package com.openswimsoftware.orm.model.list.query;

import com.openswimsoftware.orm.model.Model;
import com.openswimsoftware.orm.model.list.ModelList;

import android.content.Context;
import android.util.Log;

public class ModelListSave<E extends  Model<E>> extends ModelListQuery<E, ModelListSave<E>> {
	
	public ModelListSave(Context context, Class<E> modelType, ModelList<E> models)
	{
		super(context, modelType, models);
	}
	
	public ModelList<E> execute()
	{
		if (this.models.getUpdated())
		{
			this.dbInterface.openDB();
		
			Log.d("orm", "Save list ModelList<" + this.modelType.getSimpleName() + ">");
			
			for (E model: this.models)
			{
				model.save();
			}
		
			this.dbInterface.closeDB();
		}
		
		return this.models;
	}
	
}
